package com.mytest.leetcode;

import lombok.extern.slf4j.Slf4j;

import java.util.*;
import java.util.stream.Collectors;


/**
 * Created by shixi  on 2019/6/24
 */
@Slf4j
public class Solution217 {

    public static void main(String[] args) {
        Solution217 solution = new Solution217();
        int [] nums = {2,4,7,3,5,9};
        log.info("{}",solution.containsDuplicate2(nums));
    }


    public boolean containsDuplicate(int[] nums) {
        int length = nums.length;

        Set<Integer> checkSet = new HashSet();

        for (int i=0;i< length;i++) {
            if(checkSet.contains(nums[i])){
                return true;
            }
            checkSet.add(nums[i]);
        }
        return false;
    }

    public boolean containsDuplicate2(int[] nums) {

        Arrays.sort(nums);
        for(int i=0;i< nums.length-1;i++){
            if(nums[i]== nums[i+1]) {
                return true;
            }
        }
        return false;
    }
}

